package service.local.beans;

import java.util.List;

import javax.ejb.DependsOn;
import javax.ejb.EJB;
import javax.ejb.Stateless;

import model.Department;
import repository.DepartmentRepository;
import repository.exceptions.RepositoryException;
import service.ServiceException;
import service.local.DepartmentService;
@Stateless (name = "DepartmentService", mappedName = "DepartmentService")
@DependsOn ({"DepartmentRepository"})
public class DepartmentServiceBean implements DepartmentService {
	
	@EJB
	DepartmentRepository repo;
	@Override
	public Department insertDepartment(Department Department){
		Department r=new Department();
		try {
			return repo.save (Department);
		} catch (final RepositoryException ex) {
			//throw new ServiceException("Insert Department failed", ex);
		}
		return r;
	}

	@Override
	public Department updateDepartment(Department Department){
		try {
			repo.merge(Department);
			return Department;
		} catch (RepositoryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}

	@Override
	public void deleteDepartment(Department Department){
		try {
			repo.delete(Department);
		} catch (RepositoryException e) {
			
		}
	}

	@Override
	public List<Department> getAll(){
		try {
			return repo.getAll();
		}catch(final RepositoryException ex) {
			
		}
		return null;
	}

	@Override
	public Department getDepartmentByName(String department) {
		try {
			return repo.getDepartmentByName(department);
		}catch(final RepositoryException ex) {
			
		}
		return null;
	}
	
	



}
